﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MAPDavy.Entities;
using MAPDavy.Repository;
using Microsoft.Practices.Unity;

namespace MAPDavy.BusinessLogic
{
    public class MatriculaBL:IMatriculaBL
    {
        [Dependency]
        public IMatriculaRepository MatriculaRepository { get; set; }

        public List<MatriculaDTO> GetFromMatriculaByCriterioAndAnioAndSeccionId(string criterio, int seccionId, int anio)
        {
            return MatriculaRepository.GetFromMatriculaByCriterioAndAnioAndSeccionId(criterio, seccionId, anio);
        }


        public Matricula GetFromMatriculaById(int id)
        {
            return MatriculaRepository.GetFromMatriculaById(id); 
        }


        public void RegistrarMatricula(Matricula matricula)
        {
            if (matricula.Id == 0)
            {
                var mat = MatriculaRepository.GetFromMatriculaByAnioAndStudentId(matricula.Anio, matricula.StudentId);
                if (mat != null)
                {
                    throw new Exception("Este Alumno ya esta Incrito en el Año: " + mat.Anio);   
                }
                else
                {
                    MatriculaRepository.RegistrarMatricula(matricula);   
                }
            }
            else
            {
                MatriculaRepository.RegistrarMatricula(matricula);
            }
              
        }

        public List<Student> GetFromStudentByStudentId(string studentId, Int32 limit)
        {
            return MatriculaRepository.GetFromStudentByStudentId(studentId,limit); 
        }

        public List<Student> GetFromStudentByFirtsName(string firtsName, Int32 limit)
        {
            return MatriculaRepository.GetFromStudentByFirtsName(firtsName,limit);
        }

        public List<Student> GetFromStudentByLastName(string lastName, Int32 limit)
        {
            return MatriculaRepository.GetFromStudentByLastName(lastName,limit);
        }


        public void DeleteMatricula(int id)
        {
            MatriculaRepository.DeleteMatricula(id);
        }


        public bool CanDelete(int id)
        {
            return MatriculaRepository.CanDelete(id);  
        }


        public int AddMatricula(Matricula matricula)
        {
            return MatriculaRepository.AddMatricula(matricula);
        }
    }
}
